home *** CD-ROM | disk | FTP | other *** search
- Path: diku.dk!null
- From: null@diku.dk (Niels Ull Jacobsen)
- Newsgroups: comp.lang.c++
- Subject: Re: Function body banned in .H file - Can I still inline?
- Date: 14 Jan 1996 13:53:42 GMT
- Organization: Department of Computer Science, U of Copenhagen
- Sender: null@tyr.diku.dk
- Message-ID: <4db1t6$73g@odin.diku.dk>
- References: <4d0ir0$68e@newsroom.hitc.com>
- NNTP-Posting-Host: odin.diku.dk
- X-Newsreader: NN version 6.5.0 #13
-
- Chris Ruegger <cruegger@eos.hitc.com> writes:
-
- >I am not permitted to put any function bodies into the .H file for a class.
- >Question:
- > I would still like to make the small accessor routines inline. What
- > is my recourse, if any?
-
- None. Either you put them in some kind of .h file, or you lose the
- inlining. Or you can manually put it in *every* cpp file which uses
- the function (Not recommended!). Put them in an .inl file which you
- #include in the .h file :-)
-
- // foo.h
- // #define FOO_INLINE // uncomment to inline small functions
-
- class CFoo
- {
- int foo();
- }
-
- #ifdef FOO_INLINE
- #include "foo.inl"
- #endif
-
- ---
- // foo.inl
-
- #ifdef FOO_INLINE
- #define FOO_INLINE_SPECIFIER inline
- #else
- #define FOO_INLINE_SPECIFIER
- #endif
-
- FOO_INLINE_SPECIFIER int CFoo::foo() { return 1; }
-
- ---
- // foo.cpp
- #include "foo.h"
-
- #ifndef FOO_INLINE
- #include "foo.inl"
- #endif
-
- ...
-
-
- Actually, I think you *could* then inline them in a single cpp file without
- inlining them in the rest of the project by doing
-
- // bar.cpp
- #include "bar.h"
- #include "foo.h"
-
- #ifndef FOO_INLINE
- // we want them inline anyway
- #define FOO_INLINE
- #include "foo.inl"
- #endif
-
- bar.cpp would then end up with it's own private copy of these
- functions.
-
-
-
- >Thanks,
- >Chris
-
-
-
-
- >---------------------------------------------------------------------
- >Christopher Ruegger phone: (301) 925-1164
- > Email: cruegger@eos.hitc.com
- > car@access.digex.com
-
- --
- Niels Ull Jacobsen, Dep. of CS, U of Copenhagen (null@diku.dk)
- Roenne Alle 3 st.th, 2860 Soeborg, Denmark, tel. +45 39 66 39 86
-
-